package com.example.controller;

import com.example.entity.Result;
import com.example.entity.SysDictData;
import com.example.service.ISysDictDataService;
//import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(value = "字典管理", description = "用于字典的增删改查管理")
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController {

    @Autowired
    private ISysDictDataService dictDataService;

    @GetMapping("/list")
    public Result<List<SysDictData>> list(SysDictData dictData) {
        return Result.success(dictDataService.selectDictDataList(dictData));
    }

    @GetMapping("/type/{dictType}")
    public Result<List<SysDictData>> listByType(@PathVariable String dictType) {
        return Result.success(dictDataService.selectDictDataByType(dictType));
    }

    @GetMapping("/{dictCode}")
    public Result<SysDictData> getInfo(@PathVariable Long dictCode) {
        return Result.success(dictDataService.selectDictDataById(dictCode));
    }

    @PostMapping
    public Result<Integer> add(@RequestBody SysDictData dictData) {
        return Result.success(dictDataService.insertDictData(dictData));
    }

    @PutMapping
    public Result<Integer> edit(@RequestBody SysDictData dictData) {
        return Result.success(dictDataService.updateDictData(dictData));
    }

    @DeleteMapping("/{dictCode}")
    public Result<Integer> remove(@PathVariable Long dictCode) {
        return Result.success(dictDataService.deleteDictDataById(dictCode));
    }
}

